<%--
  Created by IntelliJ IDEA.
  User: Shir
  Date: 2024/11/7
  Time: 23:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h1>登录成功,欢迎${user.userName}</h1>
    <form action="/user/findByPage" method="get">
        <input type="hidden" name="currentPage" value="${pageInfo.currentPage}">
        <input type="hidden" name="size" value="${pageInfo.size}">
        用户名:<input type="text" name="userName" value="${userName}">
        账号:<input type="text" name="userCode" value="${userCode}">
        出生日期<input type="date" name="startDate" value="${startDate}">-<input type="date" name="endDate" value="${endDate}">
        <input type="submit">
    </form>
    <a href="/addUser.jsp">新增用户</a>
    <table border="1px">
        <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>账号</th>
            <th>地址</th>
            <th>生日</th>
            <th>性别</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${pageInfo.list}" var="user">
           <tr>
               <td>${user.id}</td>
               <td>${user.userName}</td>
               <td>${user.userCode}</td>
               <td>${user.address}</td>

               <td>
                   <fmt:formatDate value="${user.birthday}" pattern="yyyy.MM.dd"></fmt:formatDate>
               </td>
               <td>
                   <c:if test="${user.gender==1}">
                       男
                   </c:if>
                   <c:if test="${user.gender==2}">
                       女
                   </c:if>
               </td>
               <td>
                   <a href="/user/findById?id=${user.id}">修改</a>
                   <a userId="${user.id}" href="javascript:;" class="del">删除</a>
               </td>
           </tr>
        </c:forEach>

    </table>
<div class="box-footer">
    <div class="pull-left">
        <div class="form-group form-inline">
            总共${pageInfo.totalPage} 页，共${pageInfo.totalCount} 条数据。 每页
            <select id="pageSize">
                <option value="5">5</option>
                <option value="8">8</option>
                <option value="10">10</option>
            </select> 条
        </div>
    </div>

    <div>
        <a href="/user/findByPage?currentPage=1&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">首页</a>
        <a href="/user/findByPage?currentPage=${pageInfo.currentPage-1}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">上一页</a>
        <c:forEach begin="1" end="${pageInfo.totalPage}" var="pageNum">
            <c:if test="${pageNum>=pageInfo.currentPage-2&&pageNum<=pageInfo.currentPage+2}">
                <a href="/user/findByPage?currentPage=${pageNum}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">${pageNum}</a>
            </c:if>
        </c:forEach>
        <a href="/user/findByPage?currentPage=${pageInfo.currentPage+1}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">下一页</a>
        <a href="/user/findByPage?currentPage=${pageInfo.totalPage}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">尾页</a>
    </div>

</div>
</body>
<script src="/js/jquery-3.7.1.min.js"></script>
<script>
    $(function (){
        $("#pageSize").val("${pageInfo.size}")
        $("#pageSize").change(function () {
            location.href = "/user/findByPage?currentPage=1&size="+$(this).val()+"&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}";
        });
        $(".del").click(function () {
            var bo = confirm("是否删除该数据!");
            if (bo){
                $.post("/user/delete",{id:$(this).attr("userId")},function (data) {
                    alert(data.message);
                    if (data.code === 200){
                        location.href="/user/findByPage";
                    }
                },"json")
            }
        });


    })
</script>
</html>
